<template>
	<view class="content">

		<view class="" style="margin: 20rpx; display: flex; justify-content: space-between; align-content: center;">
			<view v-if="user.role != 3" class="" style="font-size: 40rpx; font-weight: 700;">
				您好:{{" " + user.name + ' ' + user.phone}}
			</view>
			<view class="">
				<button @click="tuichuAction" style="background-color: #007aff;" type="primary" size="mini">退出</button>
			</view>
		</view>

		<view class="" style="margin: 20rpx;">
			<uni-grid :column="4" :highlight="true" @change="change">
				<uni-grid-item v-for="(item, index) in dataArray" :index="index" :key="index">
					<view class="" style="height: 100%;">
						{{item.title}}
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>


	</view>
</template>

<script>
	import api from '../../utils/interface.js'
	import {
		title
	} from 'process';
	export default {
		data() {
			return {
				title: 'Hello',
				dataArray: [],
				user: {}
			}
		},
		onLoad() {
			this.user = uni.getStorageSync('data')
			this.getUpload()
			if (this.user.role == 1) {
				this.dataArray = [{
						title: '店铺管理'
					},

					{
						title: '管理员工'
					},
					{
						title: '档位管理'
					},
					{
						title: '商品管理'
					},
					{
						title: '设备类型'
					},
					// {
					// 	title: '添加设备'
					// },
					{
						title: '设备管理'
					},
					{
						title: '订单管理'
					}
				]
			} else if (this.user.role == 4) {
				this.dataArray = [{
					title: '商品管理'
				}]
			} else {
				this.dataArray = [{
					title: '提交订单'
				}, {
					title: '历史订单'
				}]
				if (this.user.role == 2) {
					this.dataArray.push({
						title: '设备管理'
					})
				}
			}

		},
		onShareAppMessage(res) {
			return {
				title: '橙分析',
				path: '/pages/index/index',
			}
		},

		//2.分享到朋友圈
		onShareTimeline(res) {
			return {
				title: '橙分析',
				path: '/pages/index/index',
			}
		},
		created() {

		},
		methods: {

			tuichuAction() {
				uni.clearStorageSync('data')
				uni.redirectTo({
					url: "/pages/login/login"
				})
			},
			async getUpload() {
				const config = {
					url: api.baseUrl + api.qinutoken,
					method: 'get'
				}
				const {
					data,
					code
				} = await this.$http.request(config)
				console.log(data);
				if (code == 1) {
					uni.setStorageSync('upToken', data.toke)
				}
			},
			change(e) {

				const item = this.dataArray[e.detail.index]
				if (item.title == '扫码') {
					// 调起条码扫描
					uni.scanCode({
						scanType: ['barCode'],
						success: function(res) {
							console.log('条码类型：' + res.scanType);
							console.log('条码内容：' + res.result);
						}
					});
				}
				if (item.title == '店铺管理') {
					uni.navigateTo({
						url: '/pages/addStore/addStore'
					})
				}
				if (item.title == '提交订单') {
					uni.navigateTo({
						url: '/pages/chengpush/chengpush'
					})
				}
				if (item.title == '管理员工') {
					uni.navigateTo({
						url: '/pages/addUser/addUser'
					})
				}
				if (item.title == '商品管理') {
					uni.navigateTo({
						url: '/pages/addGoods/addGoods'
					})
				}
				if (item.title == '档位管理') {
					uni.navigateTo({
						url: '/pages/addDangwei/addDangwei'
					})
				}
				if (item.title == '历史订单') {
					uni.navigateTo({
						url: '/pages/OrderList/OrderList'
					})
				}
				if (item.title == '订单管理') {
					uni.navigateTo({
						url: '/pages/ordertotal/ordertotal'
					})
				}
				if (item.title == '设备类型') {
					uni.navigateTo({
						url: '../../pagesA/addDevice/addDevice'
					})
				}
				if (item.title == '添加设备') {
					uni.navigateTo({
						url: '../../pagesA/addDeviceClassification/addDeviceClassification'
					})
				}
				if (item.title == '设备管理') {
					uni.navigateTo({
						url: '../../pagesA/deviceIn/deviceIn'
					})
				}


			}
		}
	}
</script>

<style lang="scss">
	.content {
		.uni-grid-item {
			view {
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>